'use strict';

module.exports = {
  up: async (queryInterface, Sequelize) => {
    const { STRING, INTEGER, DATE, DECIMAL, TEXT, ENUM } = Sequelize;
    
    await queryInterface.createTable('supplier_evaluations', {
      id: {
        type: INTEGER,
        primaryKey: true,
        autoIncrement: true
      },
      supplier_id: {
        type: INTEGER,
        allowNull: false,
        comment: '供应商ID'
      },
      evaluator: {
        type: STRING(50),
        allowNull: false,
        comment: '评估人'
      },
      evaluation_date: {
        type: DATE,
        allowNull: false,
        defaultValue: new Date(),
        comment: '评估日期'
      },
      quality_score: {
        type: DECIMAL(3, 2),
        allowNull: false,
        comment: '质量评分(1-5分)'
      },
      delivery_score: {
        type: DECIMAL(3, 2),
        allowNull: false,
        comment: '交货评分(1-5分)'
      },
      service_score: {
        type: DECIMAL(3, 2),
        allowNull: false,
        comment: '服务评分(1-5分)'
      },
      price_score: {
        type: DECIMAL(3, 2),
        allowNull: false,
        comment: '价格评分(1-5分)'
      },
      overall_score: {
        type: DECIMAL(3, 2),
        allowNull: false,
        comment: '综合评分(1-5分)'
      },
      evaluation_period: {
        type: STRING(50),
        allowNull: true,
        comment: '评估周期(如: 2025年Q1)'
      },
      status: {
        type: ENUM('draft', 'submitted', 'approved'),
        defaultValue: 'draft',
        comment: '评估状态: draft(草稿), submitted(已提交), approved(已审核)'
      },
      remark: {
        type: TEXT,
        allowNull: true,
        comment: '评估备注'
      },
      created_at: {
        type: DATE,
        allowNull: false,
        defaultValue: new Date()
      },
      updated_at: {
        type: DATE,
        allowNull: false,
        defaultValue: new Date()
      }
    });
  },

  down: async (queryInterface, Sequelize) => {
    await queryInterface.dropTable('supplier_evaluations');
  }
};